#ifndef __GEO_MODULE_H__
#define __GEO_MODULE_H__

#include <rtthread.h>
#include <rtgui/rtgui_app.h>
#include <rtgui/widgets/window.h>

#include <rtgui/rtgui_xml.h>
#include <dfs_posix.h>
#include <string.h>



#define  GEO_ITEM(name)		_geo_##name##_item
#define  GEO_ITEMS(name)	_geo_##name##_items

#define DEFINE_GEO_ITEMS(name, theme, controller, ...)		\
	const struct geo_item GEO_ITEM(name)[] = {##__VA_ARGS__};	\
	const struct geo_items  GEO_ITEMS(name) = {GEO_ITEM(name), sizeof(GEO_ITEM(name))/sizeof(struct geo_item), theme, controller};
#define DECLARE_GEO_ITEMS(name)	\
	const struct geo_items  GEO_ITEMS(name);


#define CONST_GEO_ITEM(name)	const struct geo_item GEO_ITEM(name)[]

#define CONST_GEO_ITEMS(name, theme, controller)		\
	const struct geo_items  GEO_ITEMS(name) = {GEO_ITEM(name), sizeof(GEO_ITEM(name))/sizeof(struct geo_item), theme, controller};

enum geo_module_idx
{
	GEO_IDX_NONE = -1,
	GEO_IDX_LIST = 0,
	GEO_IDX_CBAR,
	GEO_IDX_MENU,
	GEO_IDX_COUNT,
};


#define RED     RTGUI_RGB(0xff, 0x00, 0x00)
#define GREEN   RTGUI_RGB(0x00, 0xff, 0x00)
#define BLUE    RTGUI_RGB(0x00, 0x00, 0xff)
#define BLACK   RTGUI_RGB(0x00, 0x00, 0x00)
#define WHITE   RTGUI_RGB(0xff, 0xff, 0xff)

#define HIGH_LIGHT  RTGUI_RGB(0xff, 0xff, 0xff)
#define DARK_GREY   RTGUI_RGB(0x7f, 0x7f, 0x7f)
#define LIGHT_GREY  RTGUI_RGB(0xc0, 0xc0, 0xc0)

struct geo_theme
{
	rtgui_color_t foreground, background;
	rt_uint16_t textstyle;
	rt_uint16_t textalign;

	rt_int32_t align;
	//rt_uint16_t border;
	rt_uint16_t border_style;
};

enum geo_cmd_type
{
	GEO_CMD_NONE = 0,
	GEO_CMD_LOAD_VIEW,
	GEO_CMD_LOAD_ITEMS,
	GEO_CMD_INIT_VIEWS,
	GEO_CMD_LOAD_MENU,
	GEO_CMD_SCAN_DIR,
	GEO_CMD_SCAN_FILE,
	GEO_CMD_LOAD_CFG,

	GEO_CMD_DRAW,
	GEO_CMD_LAYOUT,
	GEO_CMD_CREATE,	


	GEO_CMD_DONE,
};

struct geo_item
{
	const char *text;
	int cmd;
	void *args;
};
typedef void (*geo_controller_t)(struct geo_module_view *view, int cmd, void *args);
struct geo_items
{	
	//const char *title;
	struct geo_item *item;
	int count;
	struct geo_theme *theme;
	geo_controller_t controller;
};

struct geo_module
{
	const char *title;
	struct geo_items *list;
	int list_count;
};

struct geo_module_view
{
	struct rtgui_widget widget;
	rt_uint32_t flag;
	char *title;
	struct geo_module_view **children;
	int count;
	struct geo_item *item;
	int index;
	struct geo_theme *theme;
	geo_controller_t controller;
	void *user_data;
	rt_uint16_t title_height, item_height;
};

struct geo_creater
{
	const char *title;
	struct geo_items *list;
	int list_count;
};

DECLARE_CLASS_TYPE(geo_module_view);
/** Gets the type of a ctrlbar */
#define GEO_MODULE_TYPE       (RTGUI_TYPE(geo_module_view))
/** Casts the object to a ctrlbar control */
#define GEO_MODULE(obj)       (RTGUI_OBJECT_CAST((obj), GEO_MODULE_TYPE, struct geo_module_view))
/** Checks if the object is a ctrlbar control */
#define RTGUI_IS_GEO_MODULE(obj)    (RTGUI_OBJECT_CHECK_TYPE((obj), GEO_MODULE_TYPE))


#define GEO_MODULE_IS_FATHER(view)		(RT_NULL != GEO_MODULE(view)->children)
#define GEO_MODULE_IS_CHILD(view)		(RTGUI_IS_GEO_MODULE(RTGUI_WIDGET(view)->parent))
#define GEO_MODULE_IS_TOP(view)


struct geo_module_view *geo_module_create(void);
rt_bool_t geo_module_controller(struct rtgui_object *object, int cmd, void *args);
//void geo_module_layout(struct geo_module_view *m, const char *title, int align);

//void geo_module_free_items(struct geo_items *items);


#endif